<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.value"
          clearable
          placeholder="请输入设备名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.status"
          clearable
          class="filter-item"
          placeholder="请选择告警状态"
          style="width: 150px"
        >
          <el-option
            v-for="item in dict.gas_warning_status"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <!--        <el-select-->
        <!--          v-model="query.type"-->
        <!--          clearable-->
        <!--          placeholder="类型"-->
        <!--          class="filter-item"-->
        <!--          style="width: 130px"-->
        <!--        >-->
        <!--          <el-option-->
        <!--            v-for="item in queryTypeOptions"-->
        <!--            :key="item.key"-->
        <!--            :label="item.display_name"-->
        <!--            :value="item.key"-->
        <!--          />-->
        <!--        </el-select>-->
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="设备名称">
            <el-input v-model="form.equipmentCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="告警状态">
            <el-select
              v-model="form.gasWarningStatus"
              filterable
              placeholder="请选择"
              style="width:97%"
            >
              <el-option
                v-for="item in dict.gas_warning_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" align="center" width="55" />
        <el-table-column v-if="columns.visible('equipmentCode')" align="center" prop="equipmentCode" label="设备名称" />
        <el-table-column v-if="columns.visible('monitorTime')" align="center" prop="monitorTime" label="监测时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.monitorTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('gasName')" align="center" prop="gasName" label="气体名称" />
        <el-table-column
          v-if="columns.visible('gasConcentration')"
          align="center"
          prop="gasConcentration"
          label="气体浓度"
        />
        <el-table-column v-if="columns.visible('gasUnits')" align="center" prop="gasUnits" label="气体单位">
          <template slot-scope="scope">{{ dict.label.gas_units[scope.row.gasUnits] }}</template>
        </el-table-column>
        <el-table-column
          v-if="columns.visible('gasMinConcentration')"
          align="center"
          prop="gasMinConcentration"
          label="低浓度告警值"
        />
        <el-table-column
          v-if="columns.visible('gasMaxConcentration')"
          align="center"
          prop="gasMaxConcentration"
          label="高浓度告警值"
        />
        <el-table-column
          v-if="columns.visible('gasWarningStatus')"
          align="center"
          prop="gasWarningStatus"
          label="告警状态"
        >
          <template
            slot-scope="scope"
          >{{ dict.label.gas_warning_status[scope.row.gasWarningStatus] }}</template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--          v-permission="['admin','gasMonitorData:edit','gasMonitorData:del']"-->
        <!--          label="操作"-->
        <!--          width="150px"-->
        <!--          align="center"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation :data="scope.row" :permission="permission" />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudGasMonitorData from '@/api/sapientialSite/gasMonitorData'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '气体监测数据',
  url: 'api/gasMonitorData',
  sort: 'id,desc',
  crudMethod: { ...crudGasMonitorData }
})
const defaultForm = {
  id: null,
  equipmentCode: null,
  monitorTime: null,
  gasName: null,
  gasConcentration: null,
  gasMagnification: null,
  gasUnits: null,
  gasMinConcentration: null,
  gasMaxConcentration: null,
  gasWarningStatus: null,
  createUser: null,
  createDate: null,
  updateUser: null,
  updateDate: null
}
export default {
  name: 'GasMonitorData',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['gas_units', 'gas_warning_status'],
  data() {
    return {
      permission: {
        add: ['admin', 'gasMonitorData:add'],
        edit: ['admin', 'gasMonitorData:edit'],
        del: ['admin', 'gasMonitorData:del']
      },
      rules: {},
      // queryTypeOptions: [
      //   { key: 'equipmentCode', display_name: '设备名称' }
      //   ],
      statusOptions: []
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      this.crud.params = {}
      if (query.value) {
        this.crud.params['equipmentCode'] = query.value
      }
      if (query.status) {
        this.crud.params['gasWarningStatus'] = query.status
      }
      return true
    }
  }
}
</script>

<style scoped>
</style>
